package controller

import (
	"basic2/basic/common"
	"log"
	"net/http"
	"strings"
)

func Register() {
	http.HandleFunc("/index", func(w http.ResponseWriter, q *http.Request) {
		log.Println("收到index请求。")
		values := q.URL.Query()
		b := values["key"]
		log.Printf("请求参数%s\n", b)
		res := "这是一个响应信息"
		result := common.Result{}
		if strings.EqualFold("true", b[0]) {
			result.Success(res)
		} else {
			result.Fail(res)
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(result.ToByte())
	})
}
